<!--一日游、跟团游-->
<template>
	<view class="day-tour-ticket-card bg-white" v-if="data">
		<view class="ticket-content" v-for="(item, index) in data.spus" :key="index">
			<!-- 左侧图片区域 -->
			<view class="ticket-image" :style="{ 'background-image': `url(${item.cover_url})` }">
				<text class="departure-tag flex-c">{{ subString(item.dep_place_name, 6, false) }}</text>
			</view>

			<view class="ticket-info flex-col c-grey-86">
				<!-- 景点标题 -->
				<view class="ticket-title text-2-ellipsis">{{ item.display_name }}</view>

				<!-- 副标题/描述文本 -->
				<view class="mb-12 text-ellipsis" v-if="item.intro">
					{{ item.intro }}
				</view>

				<!-- 标签组-->
				<view class="flex flex-nowrap mb-12 tag-wrap">
					<zjy-labels :data="item.sale_tips" key-name="title" key-bg-color="border_color" />
				</view>

				<!-- 评分和销量 -->
				<view class="rating-sales flex-a">
					<text class="rating">{{ scoreInCent(item.score_in_cent) }}</text>
					<text class="">分</text>
					<text class="dot mlr-8">·</text>
					<view class="c-grey-86">已售{{ formatSaleQuantity(item.sale_quantity) }}</view>
				</view>

				<!-- 店铺信息 -->
				<view class="shop-info flex-a mb-16">
					<image
						class="shop-icon"
						:src="imgBaseUrl + 'self-operated-icon.png'"
						v-if="item.store_self_employed"
					/>
					<text class="c-grey-86 fs-22">{{ subString(item.store_name, 10) }}</text>
					<image :src="imgBaseUrl + 'right-icon.png'" class="icon-16 ml-4 mt-2"></image>
				</view>

				<!-- 价格区域 -->
				<view class="price-action">
					<view class="price-info">
						<view class="current-price">
							<text class="price-symbol">¥</text>
							<text class="price">{{ formatAmount(item.lowest_price_in_cent) }}</text>
							<text class="price-unit">起</text>
						</view>
						<view class="discount flex-a" style="display: none">
							<text class="original-price">¥198</text>
							<text class="discount-text">优惠¥72</text>
						</view>
					</view>
					<view
						class="order-btn flex-c"
						:class="{ disabled: item.sold_out === true || item.saleable == false }"
						@click.stop="handleBookingClick(item)"
					>
						<template v-if="item.sold_out">售罄</template>
						<template v-else>订</template>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script setup lang="ts">
import { inject } from "vue"
import { formatSaleQuantity, scoreInCent, subString } from "@/mixins/mixins"
import ZjyLabels from "@/components/zjy-labels.vue"
import { formatAmount } from "@/utils/tools"
const imgBaseUrl = inject("imgBaseUrl")

const props = defineProps({
	data: {
		type: Object,
		default: () => null,
	},
})

const emit = defineEmits(["handleBooking"])

// 点击订
const handleBookingClick = (item) => {
	emit("handleBooking", item)
}
</script>

<style lang="scss" scoped>
.day-tour-ticket-card {
	border-radius: 16rpx;

	.ticket-content {
		display: flex;
		padding: 32rpx 24rpx;
		position: relative;
		&:after {
			content: "";
			display: block;
			position: absolute;
			bottom: 0;
			left: 24rpx;
			right: 24rpx;
			height: 1rpx;
			background: $c-grey-e5;
		}
		&:last-child {
			&:after {
				display: none;
			}
		}

		.ticket-image {
			position: relative;
			background-repeat: no-repeat;
			background-position: center center;
			background-size: cover;
			width: 192rpx;
			border-radius: 16rpx;
			background-color: #f5f5f5;
			margin-right: 20rpx;

			.departure-tag {
				width: 100%;
				height: 64rpx;
				position: absolute;
				left: 0;
				bottom: 0;
				color: #fff;
				font-size: 22rpx;
				background: linear-gradient(0deg, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0) 100%);
				border-bottom-left-radius: 16rpx;
				border-bottom-right-radius: 16rpx;
			}
		}

		.tag-wrap {
			height: 40rpx;
			overflow: hidden;
		}

		.ticket-info {
			width: calc(100% - 192rpx - 20rpx);
			.ticket-title {
				font-size: 30rpx;
				font-weight: 500;
				color: $c-black-1d;
				margin-bottom: 12rpx;
				line-height: 1.4;
			}

			.rating-sales {
				margin-bottom: 16rpx;
				color: #7c4a1b;

				.rating {
					font-weight: 900;
				}

				.dot {
					color: #c9cdd4;
				}

				.sold {
					font-size: 24rpx;
					color: #86909c;
				}
			}

			.shop-info {
				.shop-icon {
					width: 68rpx;
					height: 28rpx;
					margin-right: 4rpx;
					margin-top: 3rpx;
				}
			}

			.price-action {
				display: flex;
				justify-content: flex-end;
				align-items: flex-end;

				.price-info {
					display: flex;
					flex-direction: column;
					justify-content: center;
					height: 84rpx;
					align-items: flex-end;
					margin-right: 16rpx;

					.current-price {
						display: flex;
						justify-content: flex-end;
						align-items: baseline;

						.price-symbol {
							color: #fe4f2f;
						}

						.price {
							font-size: 36rpx;
							font-weight: 900;
							color: #fe4f2f;
						}

						.price-unit {
							color: #fa541c;
						}
					}

					.discount {
						.original {
							text-decoration: line-through;
							margin-right: 8rpx;
							color: $c-grey-c9;
						}

						.discount-text {
							background: url($imgBaseUrl + "discount-bg.png") no-repeat center center;
							background-size: cover;
							color: #f53f3f;
							font-size: 20rpx;
							padding: 2rpx 6rpx;
						}
					}
				}

				.order-btn {
					width: 84rpx;
					height: 84rpx;
					background: linear-gradient(90deg, #ff7229 0%, #ff5416 100%);
					border-radius: 16rpx;
					font-size: 32rpx;
					color: #fff;
					&.disabled {
						background: $c-grey-e5;
						color: $c-grey-86;
					}
				}
			}
		}
	}
}
</style>
